<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DOAddDialog.aspx.vb" Inherits="MIMS_WRS.Web.DOAddDialog"%>
<%@ Register TagPrefix="uc1" TagName="JSCalendarSetup" Src="../UserControls/JSCalendarSetup.ascx" %>
<%@ Register TagPrefix="uc1" TagName="DateTimePicker" Src="../UserControls/DateTimePicker.ascx" %>
<%@ Import namespace="MIMS_WRS.Web" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>Add Delivered Order Dialog</title>
		<LINK href="detail.css" type="text/css" rel="stylesheet" name="Default stylesheet">
			<LINK href="common.css" type="text/css" rel="stylesheet" name="Default stylesheet">
				<script language="javascript">
		<!--
		function validateBeforeSubmit() {
			var tblResult = window.document.getElementById('tblResult');
			var found = false;
			var tbody;
			var selectedRow;
			if (tblResult != null) {			
				tbody = tblResult.getElementsByTagName("TBODY");
				tbody = tbody[0];			
				for (i=0; i<tbody.rows.length; i++) {
					if (tbody.rows[i].cells[0].childNodes[0].checked) {
						found = true;
						selectedRow = tbody.rows[i];
						break;
					}
				}
			}			
			if (found == false) {
				alert('Please select an order');
				return;
			}
			
			var txtQty = window.document.getElementById('txtIssuedQty');
			var qty = parseInt(txtQty.value, 10);
			if (isNaN(qty)) {
				alert('Please enter issued quantity');
				txtQty.focus();
				return;
			} 
			if (qty <= 0) {
				alert('Issued quantity must be > 0');
				return;
			}
			
			var txtIssuedDate = window.document.getElementById('<%= calIssuedDate.InputClientID %>');
			if (txtIssuedDate.value.length == 0) {
				alert('Please enter issued date');
				txtIssuedDate.focus();
				return;
			}
			
			//var txtCustomerName = window.document.getElementById('txtCustomerName');
			var returnObj = new Object();
			returnObj.OfficeID = selectedRow.cells[0].childNodes[0].value;
			returnObj.POID = selectedRow.cells[0].childNodes[1].value;
			returnObj.OfficeName = selectedRow.cells[3].innerText;
			returnObj.SupplierCode = selectedRow.cells[4].innerText;
			returnObj.OrderNumber = selectedRow.cells[5].innerText;
			returnObj.OrderDate = selectedRow.cells[6].innerText;			
			returnObj.IssuedQty = qty;
			returnObj.IssuedDate = txtIssuedDate.value;
			returnObj.CustomerName = ""; /*txtCustomerName.value;*/
			window.returnValue = returnObj;
			window.close();			
		}
		//-->
				</script>
				<script src="../js/common.js"></script>
				<style>
				DIV#searchPanel { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 10px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: lightyellow }
				DIV#bottomPanel { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-SIZE: 10px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: black 1px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: lightyellow }
				</style>
	</HEAD>
	<body scroll="no">
		<form id="Form1" method="post" runat="server">
			<uc1:JSCalendarSetup id="JSCalendarSetup1" runat="server"></uc1:JSCalendarSetup>
			<div id="searchPanel">
				<span>Enter information to search for an order</span>
				<table class="FormTable">
					<tr>
						<td class="Label">Order number:</td>
						<td>
							<asp:TextBox id="txtOrderNo" onkeypress="NumberOnly(0)" runat="server" MaxLength="3" Columns="5"></asp:TextBox></td>
						<td class="Label">Order date:</td>
						<td><uc1:DateTimePicker id="calOrderDate" runat="server" EnableRequiredValidator="false"></uc1:DateTimePicker></td>
					</tr>
					<tr>
						<td class="Label">
							Owner:</td>
						<td>
							<asp:DropDownList id="ddlOffice" runat="server"></asp:DropDownList></td>
						<td class="Label"></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="4"><asp:Button Runat="server" ID="btnSearch" Text="search" CssClass="Button L1"></asp:Button></td>
					</tr>
				</table>
			</div>
			<div id="searchResult" style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 300px">
				<asp:Repeater Runat="server" ID="rptResult">
					<HeaderTemplate>
						<table class="FormTable" width="100%" id="tblResult">
							<thead>
								<th>
								</th>
								<th>Req No</th><th>S.Order</th>
								
								<th>
									Owner</th><th>Supp O/No</th><th>Order No</th><th>Order Date</th><th>Customer</th>
							</thead>
							<tbody>
					</HeaderTemplate>
					<ItemTemplate>
						<tr>
							<td><input type="radio" id="radSelect" name="radSelect" value='<%# DataBinder.Eval(Container.DataItem, "OfficeID")%>'><input type=hidden id=hidPOID value='<%# DataBinder.Eval(Container.DataItem, "ID")%>'></td>
							<td><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "REQ")).PadLeft(4, "0"c)%></td>
							<td><%# Utilities.GetNormalText(DataBinder.Eval(Container.DataItem, "SalesOrder")).PadLeft(5, "0"c)%></td>
							<td><%# DataBinder.Eval(Container.DataItem, "OfficeName")%></td>
							<td><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "PONo_Supplier")).PadLeft(3, "0"c) %></td>							
							<td><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "PONo_Number")).PadLeft(3, "0"c) %></td>
							<td><%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "OrderDate")).ToShortDateString()%></td>
							<td><%# DataBinder.Eval(Container.DataItem, "CustomerOrLocation")%></td>
						</tr>
					</ItemTemplate>
					<FooterTemplate>
						</tbody> </table>
					</FooterTemplate>
				</asp:Repeater>
			</div>
			<div id="bottomPanel">
				<span>Then enter quantity and issued date</span>
				<table class="FormTable" width="100%">
					<tr>
						<td class="Label" nowrap><span class="Required">*</span>
							Issued Qty. Units:</td>
						<td>
							<input type="text" onkeypress="NumberOnly(0)" id="txtIssuedQty" MaxLength="5" size="10">
						</td>
						<td class="Label" nowrap><span class="Required">*</span>
							Issued Date:</td>
						<td width="98%">
							<uc1:DateTimePicker id="calIssuedDate" runat="server" EnableRequiredValidator="false"></uc1:DateTimePicker></td>
					</tr>
					<tr>
						<td colspan="4" align="center" height="40"><input type="button" onclick="validateBeforeSubmit()" ID="btnOK" value="OK" Class="Button L1">&nbsp;<input type="button" onclick="window.close();" value="Cancel" class="Button L1"></td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</HTML>
